package models

import (
	"github.com/goravel/framework/database/orm"
	"goravel/app/models/common"
)

type Ticket struct {
	orm.Model
	RepairID       uint               `gorm:"column:repair_id" form:"repair_id" json:"repair_id"`
	RepairWay      int                `gorm:"column:repair_way;comment:维修方式:1门店，2现场应急" form:"repair_way" json:"repair_way"`
	ParkingID      uint               `gorm:"column:parking_id" form:"parking_id" json:"parking_id"`
	UserID         uint               `gorm:"column:user_id" form:"user_id" json:"user_id"`
	ConfirmID      uint               `gorm:"column:confirm_id" form:"confirm_id" json:"confirm_id"`
	KindID         uint               `gorm:"column:kind_id" form:"kind_id" json:"kind_id"`
	TicketType     int                `gorm:"column:ticket_type;comment:工单类型:1正常2异常" form:"ticket_type" json:"ticket_type"`
	CurrentProcess uint               `gorm:"column:current_process;comment:当前环节" form:"current_process" json:"current_process"`
	CustomerSign   string             `gorm:"column:customer_sign;comment:客户签名" form:"customer_sign" json:"customer_sign"`
	UserSign       string             `gorm:"column:user_sign;comment:维修工签名" form:"user_sign" json:"user_sign"`
	State          int                `gorm:"column:state;default:1;comment:'工单状态:正常工单：0未派单1已派单2双方签字3班长确认4完结，异常工单：1已派单2双方签字3班长确认4作业长签字5完结'" form:"state" json:"state"`
	AddServicesIds common.IDs         `gorm:"column:add_services_ids;comment:新增服务项目ID" form:"add_services_ids" json:"add_services_ids"`
	AddUsersIds    common.IDs         `gorm:"column:add_users_ids;comment:新增维修工ID" form:"add_users_ids" json:"add_users_ids"`
	HandScoreIds   common.ScoreAssign `gorm:"column:hand_score_ids;comment:新增工时ID" form:"hand_score_ids" json:"hand_score_ids"`
	Processes      []Process          `gorm:"foreignKey:TicketID;references:ID" form:"processes" json:"processes"` // 一对多关系
	Users          []User             `gorm:"many2many:ticket_user;" form:"users" json:"users"`
	Services       []Service          `gorm:"many2many:ticket_service;" form:"services" json:"services"`
	Repair         Repair             `gorm:"foreignKey:RepairID;references:ID" form:"repair" json:"repair"`
	Kind           Kind               `gorm:"foreignKey:KindID;references:ID" form:"kind" json:"kind"`
	Process        Process            `gorm:"foreignKey:CurrentProcess;references:ID" form:"process" json:"process"`
	ConfirmUser    User               `gorm:"foreignKey:ConfirmID;references:ID" form:"confirm_user" json:"confirm_user"`
	ParkingStates  []ParkingState     `gorm:"foreignKey:TicketID;references:ID" form:"parking_states" json:"parking_states"`
	Parking        Parking            `gorm:"foreignKey:ParkingID;references:ID" form:"parking" json:"parking"`
	Records        []Record           `gorm:"foreignKey:TicketID;references:ID" form:"records" json:"records"`
	orm.SoftDeletes
}
